package com.ibiaoke.goods.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.utils.StringUtils;
import com.ibiaoke.goods.entity.Check;
import com.ibiaoke.goods.entity.CheckExample;
import com.ibiaoke.goods.mapper.CheckMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public class CheckDao extends BaseDao<Check, CheckExample, Integer, CheckMapper> {

    @Autowired
    private CheckMapper checkMapper;

    @Override
    public CheckMapper getMapper() { return checkMapper; }

    public List<Check> findCheckList(String goodName, Integer goodId, Date checkStartTime,Date checkEndTime,Integer shopId, Page page) {

        CheckExample example = new CheckExample();
        CheckExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(goodName)) {
            criteria.andGoodNameLike("%" + goodName + "%");
        }

        if (goodId != null) {
            criteria.andGoodIdEqualTo(goodId);
        }

        if (checkStartTime != null) {
            criteria.andCheckTimeGreaterThanOrEqualTo(checkStartTime);
        }

        if(checkEndTime != null){
            criteria.andCheckTimeLessThanOrEqualTo(checkEndTime);
        }

        if (shopId != null) {
            criteria.andShopIdEqualTo(shopId);
        }

        page.setTotalCount(checkMapper.countByExample(example));
        example.setLimitStart(page.limitStart());
        example.setLimitEnd(page.limitEnd());
        example.setOrderByClause("create_time desc");
        return selectByExample(example);
    }
}
